const http = require('http');
const server = http.createServer();

server.on('request',(req,res) => {
  const url = req.url;//获取请求的url
  let content = '<h1>404 Not found</h1>';//设置默认的内容为404 Not found
  if(url === '/'||url === '/index.html') {
    content = '<h1>首页</h1>';//用户请求的是首页
  } else if (url === '/about.html') {
    content = '<h1>关于页面</h1>';//用户请求的是关于页面
  }
  res.setHeader('Content-Type','text/html;charset=utf-8');//设置Content-Type响应头
  res.end(content);//把内容发送给客户端
})

server.listen(80,() => {
  console.log("http server running at http://127.0.0.1:80");
})